//
//  PKReadingDetailViewController.m
//  PianKe
//
//  Created by mingtao on 15/10/10.
//  Copyright (c) 2015年 mingtao. All rights reserved.
//

#import "PKReadingDetailViewController.h"
#import "PKRequestManager.h"
#import "PKImageModel.h"
#import "PKReadingScouView.h"
#import "PKReadingTableViewControllerCell.h"

@interface PKReadingDetailViewController ()<UIWebViewDelegate>

@property(nonatomic,strong)PKReadingScouView *readingScouView;

@property(nonnull,strong)PKImageModel *imageModel;

@property(nonatomic,strong)UIWebView *uiweb;


@end

@implementation PKReadingDetailViewController


-(void)reqestImage
{
    NSMutableDictionary *Dic=[NSMutableDictionary dictionary];
    
    Dic[@"contentid"]=self.strtype;
    
    [PKRequestManager requestWithType:POST urlString:@"http://api2.pianke.me/article/info" parDic:Dic finish:^(NSData *data) {
        
        
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        
        _imageModel=[[PKImageModel alloc]init];
        
        [_imageModel setValuesForKeysWithDictionary:dic[@"data"]];
        
       self.tyID = _imageModel.typeID;
        NSLog(@"%@",self.tyID);
       // NSLog(@"%@",dic[@"data"]);
      //  NSLog(@"%@",_imageModel.typeID);
        NSString *strHTML = [NSString stringWithFormat:@"%@%@",@"http://pianke.me/webview/",_imageModel.contentid];
        
        _uiweb=[[UIWebView alloc]initWithFrame:self.view.bounds];

        
        [_uiweb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:strHTML]]];
        
        _uiweb.delegate=self;

        
        [self.view addSubview:_uiweb];
        
        
    } error:^(NSError *error) {
        
        NSLog(@"ReadingDetailViewController数据请求失败%@",error);
        
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
   // _navi.navigationBar.hidden = YES;
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIBarButtonItem *batItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(fanhui:)];
    
    self.navigationItem.leftBarButtonItem = batItem;
    
    [self reqestImage];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/




-(void)fanhui:(UIBarButtonItem *)butItem
{
    self.navigationController.navigationBar.hidden = YES;
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    
    
    /*

     
     */

}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    
    //当我们想要获取更多的webview的信息的时候，可以通过stringByEvaluatingJavaScriptFromString这个方法获取，其中的字符串参数是一个js命令，把js命令给这个Webview获取一些信息就是webview和js的交互
    CGFloat webHeight= [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]floatValue];
    
    // [uiweb loadHTMLString:strHTML baseURL:nil];
    
    // UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIHES, 60)];
    
    
    UIButton *but=[UIButton buttonWithType:(UIButtonTypeCustom)];
    
    but.frame = CGRectMake(WIHES/2-50, webHeight, WIHES/2+50, 30);
    
    [but setTitle:@"查看“访谈”的全部文章->" forState:(UIControlStateNormal)];
    
    [but addTarget:self action:@selector(Butcklike:) forControlEvents:(UIControlEventTouchUpInside)];
    //[view addSubview:but];
    [_uiweb.scrollView addSubview:but];
    _uiweb.scrollView.contentSize = CGSizeMake(WIHES, webHeight+30);
    
   // NSLog(@"%f",webHeight);
    // NSLog(@"%f",webView stringByEvaluatingJavaScriptFromString:@"");
    
}

-(void)Butcklike:(UIButton *)but
{
    PKReadingTableViewControllerCell *readingmol=[[PKReadingTableViewControllerCell alloc]init];
    readingmol.strID=self.tyID;
    NSLog(@"%@",self.tyID);
    [self.navigationController pushViewController:readingmol animated:YES];
}

@end
